package com.hs.mobile.dao.icon;

import java.util.List;

import com.hs.mobile.model.Icon;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import java.util.Date;
import java.util.List;

public class IconDAOImpl  implements IconDAO {

	SessionFactory sessionFactory;	
	//setter sessionFactory
	/**
	 * 
	 * @param sessionFactory
	 */
	public void setSessionFactory( SessionFactory sessionFactory )
	{
		this.sessionFactory = sessionFactory;
	}
	
	//getter sessionFactory
	/**
	 * 
	 * @return sessionFactory
	 */
	public SessionFactory getSessionFactory()
	{
		return sessionFactory;		
	}
	
	@Override
	public List getListAll() {
		// TODO Auto-generated method stub
		System.out.println("__ Get ALL ICONS __");
		Session session = getSessionFactory().openSession();
		List<Icon> listIcons = null;
		try {
			Criteria cr = session.createCriteria(Icon.class);
			listIcons = cr.list();
			System.out.println("__ get List ICON successfull __");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("__ ERROR __");
		} finally {
			session.close();
		}
		return listIcons;
	}

	@Override
	public Object getById(long id) {
		// TODO Auto-generated method stub
		System.out.println("__ GET ICON BY ID __");
		Session session = getSessionFactory().openSession();
		Icon icon = null;
		try {
			icon = (Icon) session.get(Icon.class, id);
			System.out.println("__ OK __");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("__ ERROR __");
		} finally {
			session.close();
		}
		return icon;
	}

	@Override
	public void add(Object obj) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Object obj) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Object obj) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Icon findByIconId(long id) {
		// TODO Auto-generated method stub
		System.out.println("__ GET ICON BY ID __");
		Session session = getSessionFactory().openSession();
		Icon icon = null;
		try {
			icon = (Icon) session.get(Icon.class, id);
			System.out.println("__ OK __");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("__ ERROR __");
		} finally {
			session.close();
		}
		return icon;
	}

}
